/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: PlainLogPrinter.java 378 2007-02-08 23:30:38Z jacek.kolezynski $
 */
package logmatcher.analyzers;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 *  Prints out incoming messages (of unknown content) to the current logger. Uses ToStringBuilder from commons-lang
 *  to retrive message fields.
 *
 *  @version $Revision: 378 $
 *
 *  @see ReflectionToStringBuilder
 *  @see ToStringBuilder
 */
public class PlainLogPrinter extends AnalyzerSkeleton {
    //~ Static fields/initializers -------------------------------------------------------------------------------------

    /** Class logger */
    private static final Log LOGGER = LogFactory.getLog(PlainLogPrinter.class);

    //~ Instance fields ------------------------------------------------------------------------------------------------

    /**
     *  Style of the output creation.
     *
     *  @see ToStringStyle
     */
    private ToStringStyle style = ToStringStyle.MULTI_LINE_STYLE;

    //~ Constructors ---------------------------------------------------------------------------------------------------

/**
     * Creates a new PlainLogPrinter object.
     */
    public PlainLogPrinter() {
        super();
    }

    //~ Methods --------------------------------------------------------------------------------------------------------

    /**
     *  
     *  @see logmatcher.LogEventListener#receiveLogEvent(java.lang.Object)
     */
    public void receiveLogEvent(Object message) {
        LOGGER.info(ToStringBuilder.reflectionToString(message, style));
    }


    /**
     *  Get output style.
     *
     *  @return configured style of the output.
     */
    public ToStringStyle getStyle() {
        return style;
    }


    /**
     *  Set output style.
     *
     *  @param style the style to set
     */
    public void setStyle(ToStringStyle style) {
        this.style = style;
    }
}
